import 'package:baichuan/baichuan.dart';

class BaichuanSdkUtils {
  static BaichuanSdkUtils? _instance;

  static BaichuanSdkUtils getInstance() {
    if (_instance == null) {
      _instance = new BaichuanSdkUtils._();
    }
    return _instance!;
  }

  BaichuanSdkUtils._();

  Future<InitResultModel> init() {
    return BCHandler.asyncInit();
  }

  // 打开登录
  Future<LoginResultModel> showLogin() {
    return BCHandler.showLogin();
  }

  // 登出
  Future<LoginResultModel> logout() {
    return BCHandler.logout();
  }

  // 是否登录
  Future<IsLoginResultModel> isLogin() {
    return BCHandler.isLogin();
  }

  // 获取淘宝用户信息
  Future<GetUserInfoResultModel> getUserInfo() {
    return BCHandler.getUserInfo();
  }

  // 打开普通电商页面
  Future<OpenResultModel> openByUrl(String detailUrl,
      {AlibcTaokeParams? taoke, AlibcShowParams? show, Map? trackParams}) {
    return BCHandler.openByUrl(
        detailUrl: detailUrl,
        taoke: taoke,
        show: show,
        trackParams: trackParams);
  }

  // 打开授权
  void openAuthorize(String url) async {
    var _isLogin = await isLogin();
    if (_isLogin.isLogin == false) {
      LoginResultModel login = await showLogin();
      if (login.status == false) {
        return;
      }
    }
    openByUrl(url);
  }
}
